package net.huashitong.supervision.task.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.supervision.task.entity.SysDeptLog;
import net.huashitong.supervision.task.filter.LogFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ling
 * Date: 2020/1/14
 * Time: 14:21
 * To change this template use File | Settings | File Templates.
 * Description:
 */
@Repository
public class SysDeptLogDao extends StringDao<SysDeptLog> {
    public List<SysDeptLog> queryFilter(LogFilter filter) {
        GenericQuery obj = createQuery("obj");
        if (StringUtils.isNotBlank(filter.getName())){
            obj.append(" and deptName like:name").setParam("name", StringUtils.getLikewords(filter.getName()));
        }
        if (StringUtils.isNotBlank(filter.getUserName())){
            obj.append(" and userName =:userName").setParam("userName", filter.getUserName());
        }
        if (StringUtils.isNotBlank(filter.getStartTime())){
            obj.append(" and dateTime >=:startTime").setParam("startTime", filter.getStartTime());
        }
        if (StringUtils.isNotBlank(filter.getEndTime())){
            obj.append(" and dateTime <=:endTime").setParam("endTime", filter.getEndTime());
        }
        if (StringUtils.isNotBlank(filter.getContent())){
            obj.append(" and content like:content").setParam("content",StringUtils.getLikewords(filter.getContent()));
        }
        return obj.listResult(filter);
    }
}
